package com.jushu.storbox.util;

import android.annotation.SuppressLint;
import net.sourceforge.pinyin4j.PinyinHelper;

public class PingYinUtil {
	
	private final static char defaultChar = '#';
	public final static String defaultStr = "#";

	@SuppressLint("DefaultLocale")
	public static String convertFirstCharToString(String string) {
		char charValue = defaultChar;
		
		if(string == null || string.length() <= 0) {
			return defaultStr;
		} else {
			charValue = string.charAt(0);
		}
		
		debugInfo(charValue);
		
		String strValue = String.valueOf(charValue);
		if(matchNumber(strValue)) {
			return defaultStr;
		} else if(matchEnglish(strValue)) {
			return strValue.toUpperCase();
		} else if(matchChines(strValue)) {
			String[] pingYinArr = PinyinHelper.toHanyuPinyinStringArray(charValue);
			charValue = pingYinArr[0].charAt(0);
			strValue = String.valueOf(charValue);
			return strValue.toUpperCase();
		} else {
			return defaultStr;
		}
	}

	private static void debugInfo(char value) {
//		System.out.println(value);
	}

	private static boolean matchChines(String value) {
		String regEx = "[\\u4e00-\\u9fa5]";
		if(value.matches(regEx)) {
			return true;
		} else {
			return false;
		}
	}
	
	private static boolean matchEnglish(String value) {
		String regEx = "[a-z]|[A-Z]";
		if(value.matches(regEx)) {
			return true;
		} else {
			return false;
		}
	}
	
	private static boolean matchNumber(String value) {
		String regEx = "[0-9]";
		if(value.matches(regEx)) {
			return true;
		} else {
			return false;
		}
	}
}
